local Exception =require("demo.exception.exception")
local DBException =require("demo.exception.db_exception")
local ParamException =require("demo.exception.param_exception")
require("util.PrintUtil")
local util = require "util.util"


-----------需要捕捉异常的业务运行代码---------
function bizFunc (arg )

    print("发生业务错误"..#arg)

   -- DBException.throwEx({msg="错误消息",status=200})
   -- DBException.throwEx({msg="错误消息",status=404})
    return "hello";
   -- DBException:throwEx({})
end
--------catch 异常代码 ---------
function catchFunc (err )

    print("捕捉异常");
    print("catchFunc 打印错误堆栈>>>>:"..debug.traceback());



    --ngx.say("输出结果")
    if err == nil then
        --ngx.say("err是nuil")
        print("在catch 中没有捕捉到异常对象")
    else
        --ngx.say("err是nuil")
        print("在catch 捕捉到异常对象 类型是"..type(err))
        if type(err) =="table" then

            --ngx.say(tostring(err.string()))

            --printTable(err)

            Exception.writeResponse(err);
        elseif type(err) =="string" then
            print("值是"..err)
        end



    end
end


----------调用封装的异常捕捉代码-----------
local flag,err = Exception:try(
        bizFunc,catchFunc
        , 1
)
print(flat);





